export default {
	isOpen: false,
	isScan: false,
	openBluetooth() {
		let _this = this;
		uni.openBluetoothAdapter({
			success(res) {
				console.log("success res: ", res);
				_this.isOpen = true;
				_this.startScan();
			},
			fail(res) {
				console.log("fail res: ", res);
				_this.isOpen = false;
			}
		})
	},
	closeBluetooth() {
		let _this = this;
		console.log("closeBluetooth");
		uni.closeBluetoothAdapter({
			success(res) {
				console.log("closeBluetooth success res: ", res);
				_this.isOpen = false;
			},
			fail(res) {
				console.log("closeBluetooth fail res: ", res);
			}
		})
	},
	startScan() {
		let _this = this;
		this.list = [];
		uni.startBluetoothDevicesDiscovery({
			success(res) {
				console.log("startScan success res: ", res);
				_this.isScan = true;
				uni.onBluetoothDeviceFound(function(res) {
					// console.log("DeviceFound res: ", res);
					_this.list = [..._this.list, ...res.devices]
				})
			},
			fail(res) {
				console.log("startScan fail res: ", res);
			}
		})
	},
	stopScan() {
		let _this = this;
		uni.stopBluetoothDevicesDiscovery({
			success(res) {
				console.log("stopScan success res: ", res);
				_this.isScan = false;
			},
			fail(res) {
				console.log("stopScan fail res: ", res);
			}
		})
	}
}
